//
//  SITableViewCell.m
//  UI_12UITableViewCellHomeworkFirst
//
//  Created by dllo on 16/6/21.
//  Copyright © 2016年 司昌宝. All rights reserved.
//

#import "SITableViewCell.h"
#import "Movie.h"
#define kWidth self.contentView.frame.size.width
#define kHeight self.contentView.frame.size.height


@interface SITableViewCell ()

@property (nonatomic,retain) UIImageView *movieImageView;
@property (nonatomic,retain) UILabel *nameLabel;
@property (nonatomic,retain) UILabel *idLabel;

@end



@implementation SITableViewCell

-(void)dealloc{
    [_nameLabel release];
    [_movieImageView release];
    [_idLabel release];
    [_movie release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.movieImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.movieImageView];
        [_movieImageView release];
        
        self.nameLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.nameLabel];
        [_nameLabel release];
        
        self.idLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.idLabel];
        [_idLabel release];
        
        
    }
    return self;
}


-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.movieImageView.frame = CGRectMake(10, 10, kWidth * 0.3, kHeight - 20);
    self.movieImageView.backgroundColor = [UIColor blackColor];
    
    self.nameLabel.frame = CGRectMake(10 + kWidth * 0.3, 20, kWidth * 0.5, kHeight * 0.4 - 10);
    self.nameLabel.backgroundColor = [UIColor orangeColor];
    
    self.idLabel.frame = CGRectMake(10 + kWidth * 0.3, 10 + kHeight * 0.5, kWidth * 0.5, kHeight * 0.4 - 10);
    self.idLabel.backgroundColor = [UIColor yellowColor];
    
    
}

-(void)setMovie:(Movie *)movie{
    if(_movie != movie){
        [_movie release];
        _movie = [movie retain];
    }
    NSURL *url = [NSURL URLWithString:movie.pic_url];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *image = [UIImage imageWithData:data];
    
    _movieImageView.image = image;
    _nameLabel.text = movie.movieName;
    _idLabel.text = movie.movieId;
}



@end
